home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / lib / cryptsetup / scripts / decrypt_opensc < prev    next >
Text File  |  2009-10-14  |  1KB  |  48 lines

  1. #!/bin/sh
  2.  
  3. # Why not use "openct-tool rwait" instead of polling opensc-tool exit status?
  4. # Well openct daemon has to be running which interferes with pcscd since both
  5. # implement reader drivers, my particular CCID reader (SCM SCR331-LC1) doesn't
  6. # work with the CCID driver in openct, however it does work with pcscd.
  7.  
  8. # Why not use "opensc-tool --wait" instead of polling opensc-tool exit status?
  9. # Although opensc-tool --help reports that there is a --wait option, it doesn't
  10. # seem to be implemented.
  11.  
  12. check_card() {
  13.     cardfound=0
  14.  
  15.     cardtmp=$(/usr/bin/opensc-tool -n 2>&1)
  16.     if [ $? == 0 ] ; then
  17.         cardfound=1
  18.     fi
  19. }
  20.  
  21. wait_card() {
  22.     check_card
  23.     if [ $cardfound == 0 ] ; then
  24.         echo "Waiting for Smart Card..." >&2
  25.         tries=0
  26.         while [ $cardfound == 0 -a $tries -lt 60 ] ; do
  27.             sleep 1
  28.             check_card
  29.             tries=$(($tries + 1))
  30.         done
  31.         if [ $cardfound == 0 ] ; then
  32.             echo 'Failed to find Smart Card card!' >&2
  33.             exit 1
  34.         fi
  35.     fi
  36. }
  37.  
  38. wait_card
  39. if [ -p /dev/.initramfs/usplash_outfifo ] && [ -x /sbin/usplash_write ]; then
  40.     # Get pin number from usplash
  41.     /sbin/usplash_write "INPUTQUIET Enter pin for $crypttarget ($cryptsource): "
  42.     /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw --pin "$(cat /dev/.initramfs/usplash_outfifo)"
  43. else
  44.     # Get pin number from console
  45.     /usr/bin/pkcs15-crypt --decipher --input $1 --pkcs1 --raw < /dev/console 2> /dev/console
  46. fi
  47. exit $?
  48.